﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nancy;
using PlatWL.Models;
using Nancy.ModelBinding;
using PlatWL.Services.Services;
using Nancy.Security;
using PlatWL.Data;

namespace PlatWL.Modules.Admin
{
    public class AuthModule : AdminModule
    {
        public AuthModule(AuthManage service) : base("auth")
        {
            this.RequiresAuthentication();
            #region 后台用户管理
            Get["/userlist"] = p =>
            {
                service.User_List(ref msg, Client, page, auth_user);
                return this.Response.AsJson(msg);
            };
            Post["/useradd"] = _ =>
            {
                var new_user = this.Bind<pt_auth_user>();
                service.User_Add(ref msg, Client, auth_user, new_user);
                return this.Response.AsJson(msg);
            };
            Get["/usermodel/{id:int}"] = p =>
            {
                service.User_Model(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };
            Get["/userdel/{id:int}"] = p =>
            {
                service.User_Del(ref msg, Client, auth_user, p.id);
                return this.Response.AsJson(msg);
            };
            #endregion
            #region 后台权限管理

            //后台首页菜单
            Get["/menu"] = p =>
            {
                service.GetMenu(ref msg, Client, auth_user);
                return this.Response.AsJson(msg);
            };

            //角色列表
            Get["/rolelist"] = p =>
            {
                service.Role_List(ref msg, Client, page, auth_user);
                return this.Response.AsJson(msg);
            };
            //角色MODEL
            Get["/rolemodel/{id:int}"] = p =>
            {
                service.Role_Model(ref msg, Client, page, auth_user, p.id);
                return this.Response.AsJson(msg);
            };
            //删除角色
            Get["/roledel/{id:int}"] = p =>
            {
                service.Role_Del(ref msg, Client, page, auth_user, p.id);
                return this.Response.AsJson(msg);
            };
            //添加角色
            Post["/roleadd"] = _ =>
            {
                var new_user = this.Bind<pt_auth_role>();
                service.Role_Add(ref msg, Client, auth_user, new_user);
                return this.Response.AsJson(msg);
            };

            //角色权限
            Get["/roleauth"] = p =>
            {
                service.Role_Auth(ref msg, Client, auth_user);
                return this.Response.AsJson(msg);
            };

            #endregion

            #region 获取档案信息

            Get["/sender/list/{infotype}/{topid?0}"] = p =>
            {

                //service.Sender_List(ref msg, Client, page, p.infotype, p.topid);
                return this.Response.AsJson(msg);
            };

            #endregion

        }
    }
}